#pragma once
#include "nodes\SpriteNode.h"
#include "addons\SpriteCounter.h"
#include "SimpleHighscoreService.h"
#include <EventManager.h>

// -------------------------------------------------------------
//  HUDCounter
// -------------------------------------------------------------
class HUDCounter {

public:
	HUDCounter() {}
	HUDCounter(ds::SpriteNode* Sprites,const ds::Vec2& textPos,const ds::Rect& textRect,const ds::Vec2& pos,int digits,const ds::Color& col,bool active = true);
	HUDCounter(ds::SpriteNode* Sprites,const ds::Vec2& textPos,const ds::Rect& textRect,const ds::Vec2& pos,const ds::Rect& fontRect,int digits,const ds::Color& col,bool active = true);
	~HUDCounter() {};
	void setValue(int value) {
		spriteCounter->setCounter(value);
	}
	void setVisible(bool visible) {
		spriteCounter->setActive(visible);
		m_Sprites->setVisible(counterText,visible);
	}
	bool isScaled() const {
		return scaled;
	}
	void setScaleMode(bool active) {
		scaled = active;
		if ( active ) {
			scaleTimer = 0.0f;
		}
	}
	void updateScaling(float elapsed);
	void setScaling(float scale) {
		scaling = scale;
		spriteCounter->setScale(ds::Vec2(scaling,scaling));
	}
	int getValue() const {
		return spriteCounter->getCounter();
	}
private:
	//
	void create(const ds::Vec2& textPos,const ds::Rect& textRect,const ds::Vec2& pos,const ds::Rect& fontRect,int digits,const ds::Color& col,bool active = true);
	ds::SpriteNode* m_Sprites;
	ds::SpriteCounter *spriteCounter;
	ds::SHandle counterText;	
	// scaling
	bool scaled;
	float scaling;
	float scaleTimer;		
};

// -------------------------------------------------------------
//  HUD
// -------------------------------------------------------------
class HUD : public ds::SpriteNode , public ds::EventHandler {

public:
	HUD() : ds::SpriteNode("HUDSprites","TexturesMaterial",ds::SCM_MODULATE) , m_TTL(0) , m_Timer(true) , m_Running(false) {
		gEngine->getEventManager().registerEventHandler(this);
	}
	~HUD() {}
	void init();
	void update(float elapsed);
	void reset() {
		m_Points = 0;
		m_ScoreCounter->setCounter(0);
		m_CoverageCounter->setCounter(0);
		m_Seconds = 0;
		m_Minutes = 0;
		m_SecCounter->setCounter(0);
		m_MinCounter->setCounter(0);
	}
	void setScore(int value);	
	void setCoverage(int coverage) {
		m_CoverageCounter->setCounter(coverage);
	}
	void setTTL(int seconds) {		
		seconds == 0 ? m_Timing = false : m_Timing = true;
		m_TTL = seconds;
	}
	void process(ds::EventBuffer& buffer);	
	void activate();
	void deactivate();
private:	
	//
	ds::SHandle addStaticImage(const ds::Vec2& pos,const ds::Rect& textureRect,const ds::Color& color,bool active = true);
	//
	//ds::SpriteNode* m_Sprites;
	ds::SpriteCounter* m_ScoreCounter;
	ds::SpriteCounter* m_CoverageCounter;
	ds::SpriteCounter* m_SecCounter;
	ds::SpriteCounter* m_MinCounter;
	int m_Points;
	SimpleHighscoreService* m_HighScore;
	int m_Seconds;
	int m_Minutes;
	int m_TTL;
	bool m_Timing;
	float m_Timer;
	bool m_Running;
};

